from tortoise import BaseDBAsyncClient


async def upgrade(db: BaseDBAsyncClient) -> str:
    return """
        ALTER TABLE "tb_blog_articles" ALTER COLUMN "status" SET DEFAULT 'p';
        CREATE TABLE IF NOT EXISTS "tb_system_global_config" (
    "id" UUID NOT NULL  PRIMARY KEY,
    "active" BOOL   DEFAULT True,
    "created_at" TIMESTAMPTZ   DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ   DEFAULT CURRENT_TIMESTAMP,
    "title" VARCHAR(50) NOT NULL,
    "description" VARCHAR(255),
    "keywords" VARCHAR(255),
    "logo_text" VARCHAR(50) NOT NULL,
    "icp" VARCHAR(50),
    "sider_name" VARCHAR(50) NOT NULL,
    "sider_avatar" VARCHAR(255) NOT NULL,
    "sider_description" VARCHAR(255) NOT NULL,
    "sider_cover" VARCHAR(255) NOT NULL,
    "tag_cloud" BOOL NOT NULL  DEFAULT True,
    "recent_posts" BOOL NOT NULL  DEFAULT True,
    "time_line" BOOL NOT NULL  DEFAULT True,
    "index_title" VARCHAR(50) NOT NULL,
    "index_subtitle" VARCHAR(100) NOT NULL,
    "index_cover" VARCHAR(255) NOT NULL,
    "index_blurhash" VARCHAR(100) NOT NULL,
    "category_cover" VARCHAR(255) NOT NULL,
    "category_blurhash" VARCHAR(100) NOT NULL,
    "tag_cover" VARCHAR(255) NOT NULL,
    "tag_blurhash" VARCHAR(100) NOT NULL,
    "archive_cover" VARCHAR(255) NOT NULL,
    "archive_blurhash" VARCHAR(100) NOT NULL,
    "thought_cover" VARCHAR(255) NOT NULL,
    "thought_blurhash" VARCHAR(100) NOT NULL,
    "message_cover" VARCHAR(255) NOT NULL,
    "message_blurhash" VARCHAR(100) NOT NULL
);
COMMENT ON COLUMN "tb_system_global_config"."title" IS '网站标题';
COMMENT ON COLUMN "tb_system_global_config"."description" IS '网站描述';
COMMENT ON COLUMN "tb_system_global_config"."keywords" IS '网站关键词';
COMMENT ON COLUMN "tb_system_global_config"."logo_text" IS '网站 Logo 文字';
COMMENT ON COLUMN "tb_system_global_config"."icp" IS 'ICP 备案号';
COMMENT ON COLUMN "tb_system_global_config"."sider_name" IS '侧边栏名称';
COMMENT ON COLUMN "tb_system_global_config"."sider_avatar" IS '侧边栏头像';
COMMENT ON COLUMN "tb_system_global_config"."sider_description" IS '侧边栏描述';
COMMENT ON COLUMN "tb_system_global_config"."sider_cover" IS '侧边栏背景';
COMMENT ON COLUMN "tb_system_global_config"."tag_cloud" IS '是否显示标签云';
COMMENT ON COLUMN "tb_system_global_config"."recent_posts" IS '是否显示最新文章';
COMMENT ON COLUMN "tb_system_global_config"."time_line" IS '是否显示时间线';
COMMENT ON COLUMN "tb_system_global_config"."index_title" IS '首页标题';
COMMENT ON COLUMN "tb_system_global_config"."index_subtitle" IS '首页副标题';
COMMENT ON COLUMN "tb_system_global_config"."index_cover" IS '首页封面';
COMMENT ON COLUMN "tb_system_global_config"."index_blurhash" IS '首页封面的 blurhash';
COMMENT ON COLUMN "tb_system_global_config"."category_cover" IS '分类封面';
COMMENT ON COLUMN "tb_system_global_config"."category_blurhash" IS '分类封面的 blurhash';
COMMENT ON COLUMN "tb_system_global_config"."tag_cover" IS '标签封面';
COMMENT ON COLUMN "tb_system_global_config"."tag_blurhash" IS '标签封面的 blurhash';
COMMENT ON COLUMN "tb_system_global_config"."archive_cover" IS '归档封面';
COMMENT ON COLUMN "tb_system_global_config"."archive_blurhash" IS '归档封面的 blurhash';
COMMENT ON COLUMN "tb_system_global_config"."thought_cover" IS '随笔封面';
COMMENT ON COLUMN "tb_system_global_config"."thought_blurhash" IS '随笔封面的 blurhash';
COMMENT ON COLUMN "tb_system_global_config"."message_cover" IS '留言板封面';
COMMENT ON COLUMN "tb_system_global_config"."message_blurhash" IS '留言板封面的 blurhash';
        CREATE TABLE IF NOT EXISTS "tb_system_menus" (
    "id" UUID NOT NULL  PRIMARY KEY,
    "active" BOOL   DEFAULT True,
    "created_at" TIMESTAMPTZ   DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ   DEFAULT CURRENT_TIMESTAMP,
    "title" VARCHAR(50) NOT NULL,
    "icon" VARCHAR(50),
    "path" VARCHAR(100),
    "is_external" INT NOT NULL  DEFAULT 0,
    "sort" INT NOT NULL  DEFAULT 0,
    "parent_id" UUID REFERENCES "tb_system_menus" ("id") ON DELETE CASCADE
);
COMMENT ON COLUMN "tb_system_menus"."title" IS '菜单标题';
COMMENT ON COLUMN "tb_system_menus"."icon" IS '菜单图标';
COMMENT ON COLUMN "tb_system_menus"."path" IS '菜单路径';
COMMENT ON COLUMN "tb_system_menus"."is_external" IS '是否外链';
COMMENT ON COLUMN "tb_system_menus"."sort" IS '排序';"""


async def downgrade(db: BaseDBAsyncClient) -> str:
    return """
        ALTER TABLE "tb_blog_articles" ALTER COLUMN "status" DROP DEFAULT;
        DROP TABLE IF EXISTS "tb_system_global_config";
        DROP TABLE IF EXISTS "tb_system_menus";"""
